#include <cstdio>

typedef unsigned int uint;

inline uint ones (uint n)
{
	uint r, o;

	r = o = 1;
	while (o % n)
	{
		o *= 10;
		o += 1;
		o %= n;
		++r;
	}

	return r;
}


int main ()
{
	uint n;

	while (scanf ("%u", &n) == 1)
		printf("%u\n", ones (n));

	return 0;
}